package com.team.employment.web.admin.custom.utils;

import com.cloopen.rest.sdk.CCPRestSmsSDK;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
public class SmsUtil {
    @Value("${rong.sms.account-id}")
    private String accountSid;

    @Value("${rong.sms.auth-token}")
    private String authToken;

    @Value("${rong.sms.app-id}")
    private String appId;

    @Value("${rong.sms.template-id}")
    private String templateId;

    public boolean sendSmsCode(String phone, String captcha) {
        try {
            CCPRestSmsSDK sdk = new CCPRestSmsSDK();
            sdk.init("app.cloopen.com", "8883");
            sdk.setAccount(accountSid, authToken);
            sdk.setAppId(appId);

            HashMap<String, Object> result = sdk.sendTemplateSMS(phone, templateId, new String[]{captcha, "5"});

            if ("000000".equals(result.get("statusCode"))) {
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
